// App.java
import model.*;
import service.PaperList;
import service.exception.NoEnoughPapersException;
import service.strategy.SequentialSelectionStrategy;
import service.visitor.CountStudentsVisitor;

import java.util.Arrays;
import java.util.List;

public class App {
    public static void main(String[] args) {
        // 创建论文列表
        List<Paper> papers = Arrays.asList(
            new Thesis("Science"),
            new ConferencePaper("Science"),
            new JournalPaper("Technology")
        );
        
        // 创建PaperList对象
        PaperList listOfRainy = new PaperList("Rainy", papers);
        
        // 创建学生列表
        List<Student> students = Arrays.asList(
            new Student("Cloudy", 1, PaperType.Thesis),
            new Student("Sunny", 1, PaperType.JournalPaper),
            new Student("Windy", 2, PaperType.Any)
        );
        
        // 设置顺序选择策略
        listOfRainy.setSelectionStrategy(new SequentialSelectionStrategy());
        
        System.out.println("===== 论文选择开始 =====");
        
        // 学生选择论文
        for (Student student : students) {
            try {
                List<Paper> selected = listOfRainy.selectPaperByRandom(student);
                System.out.println("\n" + student.getName() + " 选择了:");
                for (Paper paper : selected) {
                    System.out.println(" - " + paper);
                }
            } catch (NoEnoughPapersException e) {
                System.out.println("\n" + e.getMessage());
            } catch (Exception e) {
                System.out.println("\n错误: " + e.getMessage());
            }
        }
        
        // 输出最终选择结果
        System.out.println("\n===== 最终选择结果 =====");
        System.out.println(listOfRainy.getSelectionResult());
        
        // 使用Visitor统计学生数量
        CountStudentsVisitor visitor = new CountStudentsVisitor();
        listOfRainy.getSelectionResult().accept(visitor);
        System.out.println("总共选择论文的学生人数: " + visitor.getCount());
    }
}